﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace Test_2D
{
    partial class EditForm //Form1
    {



        /*

        //判断是否为关键帧
        private bool isKeyFrame(int index)
        {
            if (this.frameState(index) == FrameState.KEY_EMPTY ||
                this.frameState(index) == FrameState.KEY_NEMPTY)
                return true;
            else
                return false;
        }

        //获取帧的状态
        enum FrameState { INEXISTENCE, NULL, NKEY_NEMPTY, KEY_EMPTY, KEY_NEMPTY, UNKNOWN }
        
        private FrameState frameState(int index)
        {
            if (index > timeline.Frames.Count - 1 || index == -1)
                return FrameState.INEXISTENCE;              //帧号超出范围
            if (timeline.Frames[index] == null)
                return FrameState.NULL;                     //帧指向null

            string str = "";
            str += timeline.Frames[index].IsKey ? 1 : 0;
            str += timeline.Frames[index].IsEmpty ? 1 : 0;

            switch (int.Parse(str))
            {
                case 00: return FrameState.NKEY_NEMPTY;     //不是关键字，不是空的
                case 10: return FrameState.KEY_NEMPTY;      //是关键字，不是空的
                case 11: return FrameState.KEY_EMPTY;       //是关键字，是空的
                default: return FrameState.UNKNOWN;         //无法判断
            }
        }

        //插入关键帧
        private void insertKeyFrame(int index)
        {
            if (!isKeyFrame(index))
            {
                int max = timeline.Frames.Count - 1;    //当前时间轴帧的长度
                if (index > max)
                {
                    for (int i = 0; i < index - max; ++i)
                        timeline.Frames.Add(null);
                }

                if (timeline.Frames[index] == null)
                {
                    timeline.Frames[index] = new Frame();   
                }
                timeline.Frames[index].IsKey = true;    //设置为空白关键帧KEY_EMPTY 

                //如果有前一个关键帧且非空，则将其下的运动元复制给新的关键帧
                int prekey = getPreKey(index);
                if (prekey != -1 && !timeline.Frames[prekey].IsEmpty)
                {
                    foreach (Motion mot in timeline.Frames[prekey].Motions)
                    {
                        timeline.Frames[index].Motions.Add(new Motion(mot));
                    }
                }
            }
        }

        //获得前一个关键帧的索引
        private int getPreKey(int index)
        {
            for (int i = index - 1; i >= 0; --i)
            {
                if (timeline.Frames[i] == null)
                    continue;

                if (timeline.Frames[i].IsKey)
                    return i;
            }
            return -1;
        }
        //获得后一个关键帧的索引
        private int getNextKey(int index)
        {
            for (int i = index + 1; i < timeline.Frames.Count; ++i)
            {
                if (timeline.Frames[i] == null)
                    continue;

                if (timeline.Frames[i].IsKey)
                    return i;
            }
            return -1;
        }


        //向listview添加元件
        private void listView_Add(Component com)
        {
            listView1.Items.Add(com.Name);
            imglist.Images.Add(com.Image);
            listView1.Items[listView1.Items.Count - 1].Tag = com;      //每个列表绑定一个元件
            listView1.Items[listView1.Items.Count - 1].ImageIndex = listView1.Items.Count - 1;
        }
        //listview删除元件
        private void listView_Del(int index)
        {
            imglist.Images.RemoveAt(index);
            listView1.Items.RemoveAt(index);
            comList.RemoveAt(index);

            foreach (ListViewItem lvi in listView1.Items)
            {
                lvi.ImageIndex = lvi.Index;
            }
        }

        //添加lable模拟帧
        int frame_index = 1;
        Point frame_start = new Point(0, 5);
        Point frame_offest = new Point(15, 0);
        
        private void addFrame(int count)
        {
            for (int i = 0; i < count; ++i)
            {
                Label lb = new Label();
                lb.AutoSize = true;
                lb.ContextMenuStrip = this.frameMenuStrip;
                lb.Location = frame_start;
                lb.Text = frame_index.ToString();
                lb.MouseDown += new System.Windows.Forms.MouseEventHandler(this.frame_MouseDown);
                this.panel3.Controls.Add(lb);
                frame_index++;
                frame_start.Offset(frame_offest);
            }
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
                return;

            panel3.Controls.Clear();
            frame_index = 1;
            frame_start = new Point(0, 5);
            addFrame(int.Parse(textBox2.Text));
        }
        private void panel3_Scroll(object sender, ScrollEventArgs e)
        {
            Panel pl = (Panel)sender;
            if (pl.HorizontalScroll.Value == pl.HorizontalScroll.Maximum - pl.HorizontalScroll.LargeChange + 1)
            {
                frame_start = panel3.Controls[panel3.Controls.Count - 1].Location;
                frame_start.Offset(frame_offest);
                addFrame(10);
            }
        }*/
    }
}
